/**
 * @file
 * @brief Autobuy widget
 * @date 2021-09-07
 */

#pragma once

#include "state.h"
#include <QStackedWidget>

class QLabel;
class QPushButton;

/**
 * @class AutoBuyUpgradeLabel
 * @brief simple widget for one bought upgrade type
 */
class AutoBuyUpgradeLabel : public QWidget
{
    Q_OBJECT
public:
    /**
     * @brief construct widget for custom upgrade type
     * @param nType upgrade type
     */
    AutoBuyUpgradeLabel( const UpgradeType nType, QWidget * parent = nullptr );

    /**
     * @brief set number of bought levels
     * @param nCount count of bought levels
     */
    void setNumber( int64_t nCount );

    /**
     * @return upgrade type
     */
    UpgradeType getType() const;

    /**
     * @brief remove info about bought levels
     */
    void reset();

private:
    QLabel * count;
    const UpgradeType type;
};

/**
 * @class AutoBuyUpgradeInfo
 * @brief QWidget class with autobuy results
 */
class AutoBuyUpgradeInfo : public QWidget
{
    Q_OBJECT
public:
    /**
     * @brief construct widget for custom upgrade types
     * @param data list of upgrades
     */
    AutoBuyUpgradeInfo( std::initializer_list<UpgradeType> data, QWidget * parent = nullptr );

    /**
     * @brief set new value for number of bought levels
     */
    void setNumber( UpgradeType nType, int64_t nCount );

    /**
     * @brief remove info about bought levels 
     */
    void reset();

signals:
    /**
     * @brief emited when "Close" button will be released
     */
    void closed();

private:
    std::vector<AutoBuyUpgradeLabel *> labels;
};

/**
 * @class AutoBuyInfo
 * @brief class for main window of autobuy widget
 */
class AutoBuyInfo : public QWidget
{
    Q_OBJECT
public:
    explicit AutoBuyInfo( QWidget * parent = nullptr );

signals:
    /**
     * @brief emit when step will be changed
     * @param step new step value
     */
    void stepChanged( int step );

    /**
     * @brief emit on release "SPEND ALL" button
     * @param type product type: XP, ASSET, POWER
     */
    void buyAll( ProductType type );
};

/**
 * @class AutoBuyWidget
 * @brief widget class for change step value and spend all resources
 */
class AutoBuyWidget : public QStackedWidget
{
    Q_OBJECT
public:
    explicit AutoBuyWidget( std::shared_ptr<State> state, QWidget * parent = nullptr );

public slots:
    /**
     * @brief spend all resource on upgrades
     * @param nType resource type: ASSET, XP, POWER
     */
    void buyAll( ProductType nType );

    /**
     * @brief update step value from player data
     * @param state player data
     */
    void updateData( const State & state );

signals:
    /**
     * @brief emit on changing step(1, 10, 100)
     * @param step new step value
     */
    void stepChanged( int step );

private:
    AutoBuyInfo * buyInfo;
    AutoBuyUpgradeInfo * labInfo;
    AutoBuyUpgradeInfo * buildInfo;
    std::shared_ptr<State> playerData;
};
